window.MaterialList = (function($,module){
    _materialPage = 'materialPage';
    
    /**
     * 初始化
     */
    function init(){
        initPageInfo();
        
        bindEvent();
    }
    
    /**
     * 加载页面
     */
    function initPageInfo(){
        //更新page信息
        var url = 'materialBaseInfo/showallmaterialbaseinfo';
        var urlP = 'materialBaseInfo/showallmaterialbaseinfo';
        var paramData = CommonUtils.serializeToJSON($(".select_text input").serializeArray());
        paramData["pageNo"]	= $("#pageNo").val()||1;
        paramData =	JSON.stringify(paramData);
        CommonUtils.getAjaxData({url:urlP,type:'POST',data:paramData},function(data){
            PageUtils.refreshPageInfo({element:_materialPage,url : url,callback : showMaterialList},data['page']);
            showMaterialList(data);
        });
    }
    
    /**
     * 显示产线列表
     */
    function showMaterialList(data){
        //显示任务模板列表
        var html = template('materialTemp', data);
        $("#materialTab").html("").html(html);
        $("tbody tr:odd").css("background", "#EBF5FF");
    }
    
    /**
     * 删除物料
     */
    function deleteMaterials(){
        var list = [];//项目中要删除的id集合
        var checks = $("input[type='checkbox']:checked");
        $.each(checks,function(index,obj){
            list.push(obj.id);
        });
        
        if (list.length == 0){
            return;
        }
        
        window.confirm("确定要删除吗?",function(result){
            if (result){
                var deleteMaterialsUrl = path + 'materialBaseInfo/deletematerialbaseinfo';
                $.ajax({
                    url : deleteMaterialsUrl,
                    data : {ids:list},
                    type : 'POST',
                    traditional: true,//这里设置为true
                	success:function(data) {
                		if(data == 'success'){
                			alert("删除成功");
                			initPageInfo();
                			//刷新当前分页数据
                			var current = PageUtils._currentPage[_materialPage];
                			PageUtils.pageClick(current,_materialPage);
                		}
                		else{
                			alert("删除失败");
                		}
                	},
                	error:function(){
	                    alert("删除失败");
	                }
                });
            }
        });
    }
    
    /**
     * 绑定事件
     */
    function bindEvent(){
    }
    
    function toInfo(materialCode){
		window.location.href=path + "materialBaseInfo/toMaterialUpdateJsp?materialCode=" + encodeURI(materialCode);
	}
    	
    module.init = init;
    module.deleteMaterials = deleteMaterials;
    module.toInfo = toInfo;
    return module;
}($, window.MaterialList || {}));
$(function() {
    MaterialList.init();
});